package com.hdu.metrics_center.TestController;


import com.alibaba.fastjson.JSON;
import com.hdu.metrics_center.metrics.MetricsExecuteResult;
import com.hdu.metrics_center.metrics.service.MetricsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class TestController {


    private static final Logger log = LoggerFactory.getLogger(TestController.class);
    private final MetricsService metricsService;

    public TestController(MetricsService metricsService) {
        this.metricsService = metricsService;
    }

    /**
     * 测试坐席休息次数
     *
     * @return
     */
    @GetMapping("agentRestCount")
    public String agentRestCount() {
        // 32183821 业务线下 12345 坐席 休息次数 + 1
        HashMap<String, Object> params = new HashMap<String, Object>() {{
            put("businessLineId", "32183821");
            put("agentNum", "12345");
            put("metricsName", "agentRestCount");
        }};
        metricsService.saveMetrics(
                "agentRestCount",
                1,
                params
        );
        // 查询 32183821 业务线下 12345 坐席 休息次数
        MetricsExecuteResult metricsExecuteResult = metricsService.queryMetrics(
                "agentRestCount",
                params
        );
        return JSON.toJSONString(metricsExecuteResult);
    }

    /**
     * 测试坐席休息列表
     *
     * @return
     */
    @GetMapping("agentRestList")
    public String agentRestList() {
        // 32183821 业务线下 12345 加入到 坐席休息列表
        HashMap<String, Object> params = new HashMap<String, Object>() {{
            put("businessLineId", "32183821");
            put("agentNum", "12345");
            put("metricsName", "agentRestList");
        }};

        metricsService.saveMetrics(
                "agentRestList",
                12345,
                params
        );

        // 32183821 业务线下 54321 加入到 坐席休息列表
        params.put("agentNum", "54321");
        metricsService.saveMetrics(
                "agentRestList",
                54321,
                params
        );


        // 查询 32183821 业务线下所有 坐席
        MetricsExecuteResult metricsExecuteResult = metricsService.queryMetrics(
                "agentRestList",
                params
        );

        String agentList = JSON.toJSONString(metricsExecuteResult);

        log.info("坐席列表 : {}" , agentList);


        // 将 54321 从 坐席休息列表里面移除
        params.put("agentNum", "54321");
        metricsService.delMetrics(
                "agentRestList",
                params
        );

        // 查询 32183821 业务线下所有 坐席
        metricsExecuteResult = metricsService.queryMetrics(
                "agentRestList",
                params
        );

        agentList = JSON.toJSONString(metricsExecuteResult);
        log.info("坐席列表 : {}" , agentList);

        return agentList;
    }

    /**
     * 测试坐席休息人数
     * @return
     */
    @GetMapping("agentRestPeopleCount")
    public String agentRestPeopleCount() {
        // 32183821 业务线下 12345 加入到 坐席休息列表
        HashMap<String, Object> params = new HashMap<String, Object>() {{
            put("businessLineId", "32183821");
            put("agentNum", "12345");
            put("metricsName", "agentRestList");
        }};

        metricsService.saveMetrics(
                "agentRestList",
                12345,
                params
        );

        // 32183821 业务线下 54321 加入到 坐席休息列表
        params.put("agentNum", "54321");
        metricsService.saveMetrics(
                "agentRestList",
                54321,
                params
        );

        MetricsExecuteResult metricsExecuteResult = metricsService.queryMetrics(
                "agentRestPeopleCount",
                params
        );

        String str = JSON.toJSONString(metricsExecuteResult);
        log.info("坐席休息人数 : {}" , str);
        return str;
    }


    /**
     * 测试坐席单次休息时长
     * @return
     */
    @GetMapping("agentSingleRestTime")
    public String agentSingleRestTime() {
        // 32183821 业务线下 12345坐席单次休息时间达到 10分钟
        HashMap<String, Object> params = new HashMap<String, Object>() {{
            put("businessLineId", "32183821");
            put("agentNum", "12345");
            put("metricsName", "agentSingleRestTime");
        }};

        metricsService.saveMetrics(
                "agentSingleRestTime",
                10,
                params
        );

        // 查询 32183821 业务线下 12345坐席单次休息时间
        MetricsExecuteResult metricsExecuteResult = metricsService.queryMetrics(
                "agentSingleRestTime",
                params
        );

        return JSON.toJSONString(metricsExecuteResult);
    }
}
